package de.pass.ch.junit;

import static de.pass.ch.util.Constants.SHORTCUT_EDGE_LIMIT;
import static org.junit.Assert.assertEquals;

import java.util.Random;

import org.junit.Test;

import de.pass.ch.graph.edge.Edge;

public class TestEdge {

	@Test
	public void testEdgeMethods() {

		int runs = 100000;
		int intMax = (1 << 26) - 1;
		int shMax = SHORTCUT_EDGE_LIMIT;

		Random r = new Random();

		int target = 0;
		int weight = 0;
		int shcM = 0;
		int shcOEC = 0;
		int shcE1 = 0;
		int shcE2 = 0;
		boolean forw = false;
		boolean backw = false;
		byte type = 0;
		Edge edge = null;

		for (int i = 0; i < runs; i++) {

			target = r.nextInt(intMax);
			weight = r.nextInt(intMax);
			shcM = r.nextInt(intMax);
			shcOEC = r.nextInt(intMax);
			shcE1 = r.nextInt(shMax);
			shcE2 = r.nextInt(shMax);
			forw = r.nextBoolean();
			backw = r.nextBoolean();
			type = (byte) r.nextInt(3);

			edge = new Edge(target, weight, type, forw, backw, shcE1, shcE2,
					shcM, shcOEC);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			target = r.nextInt(intMax);
			edge.setTarget(target);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			weight = r.nextInt(intMax);
			edge.setWeight(weight);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			shcM = r.nextInt(intMax);
			edge.setShortcutMiddle(shcM);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			shcOEC = r.nextInt(intMax);
			edge.setShortcutOriginalEdgeCount(shcOEC);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			shcE1 = r.nextInt(shMax);
			edge.setShortcutEdge1(shcE1);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			shcE2 = r.nextInt(shMax);
			edge.setShortcutEdge2(shcE2);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			forw = r.nextBoolean();
			edge.setForward(forw);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			backw = r.nextBoolean();
			edge.setBackward(backw);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

			type = (byte) r.nextInt(3);
			edge.setType(type);

			assertEquals(target, edge.getTarget());
			assertEquals(weight, edge.getWeight());
			assertEquals(shcM, edge.getShortcutMiddle());
			assertEquals(shcOEC, edge.getShortcutOriginalEdgeCount());
			assertEquals(shcE1, edge.getShortcutEdge1());
			assertEquals(shcE2, edge.getShortcutEdge2());
			assertEquals(forw, edge.isForward());
			assertEquals(backw, edge.isBackward());
			assertEquals(type, edge.getType());

		}
	}

}
